package com.lbm.baseclass.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class SpringBeanLoader implements ApplicationContextAware
{
	
	/** The context. */
	private static ApplicationContext context = null;
	
	/** The spring bean loader. */
	private static SpringBeanLoader springBeanLoader = null;

	/**
	 * Inits the.
	 *
	 * @return the spring bean loader
	 */
	public synchronized static SpringBeanLoader init()
	{
		if (springBeanLoader == null)
		{
			springBeanLoader = new SpringBeanLoader();
		}
		return springBeanLoader;
	}

	/* (non-Javadoc)
	 * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
	 */
	@Override
	public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException
	{
		context = applicationContext;
	}
	/**
	 * Gets the bean.
	 *
	 * @param beanName the bean name
	 * @return the bean
	 */
	public synchronized static Object getBean(final String beanName)
	{
		return context.getBean(beanName);
	}
}
